package com.gitee.mazhenggg.demo.gateway.config;


import com.gitee.mazhenggg.demo.gateway.filter.AccessFilter;
//import com.gitee.mazhenggg.demo.gateway.filter.TraceFilter;
//import com.gitee.mazhenggg.demo.gateway.filter.WebTraceFilter;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author mazhenggg
 */
@Slf4j
@Configuration
public class GlobalFilterConfig {

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }

    @Bean
    @ConditionalOnMissingBean(AccessFilter.class)
    //@ConditionalOnProperty(prefix = "demo.gateway.config", value = "access", havingValue = "true")
    public AccessFilter accessGatewayFilter() {
        AccessFilter accessGatewayFilter = new AccessFilter();
        log.debug("Loding Access Filter Config Bean");
        return accessGatewayFilter;
    }

//    //@Bean
//    @ConditionalOnMissingBean(TraceFilter.class)
//    public TraceFilter traceFilter() {
//        TraceFilter traceFilter = new TraceFilter();
//        log.debug("Loding Access Filter Config Bean");
//        return traceFilter;
//    }
//
//    //@Bean
//    @ConditionalOnMissingBean(WebTraceFilter.class)
//    public WebTraceFilter webTraceFilter() {
//        WebTraceFilter webTraceFilter = new WebTraceFilter();
//        log.debug("Loding Access Filter Config Bean");
//        return webTraceFilter;
//    }

}
